using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Trigger : MonoBehaviour
{
    private Camera m_Camera;
    private bool isMouseDown;
    private ScenarioTrigger scenarioTrigger;

    private void Start()
    {
        m_Camera = GameObject.Find("Main Camera").GetComponent<Camera>();
        scenarioTrigger=gameObject.GetComponent<ScenarioTrigger>();
    }

    private void OnMouseDown()
    {
        Debug.Log(1);
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log(1);
        scenarioTrigger.Trigger();
    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Ray ray = m_Camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Debug.DrawLine(ray.origin, hit.point);
                GameObject gameobj = hit.collider.gameObject;
                //注意要将对象的tag设置成collider才能检测到
                if (gameobj.tag == "collider")
                {
                    Debug.Log("点击到物体了");
                }
            }
        }
    }

}
